﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Soveryn.Commerce.BaseClasses;
using Soveryn.Commerce.Shared;

namespace Soveryn.Commerce.Doodads
{

    public partial class ImageGallery : DoodadBaseClass
    {

        new protected void Page_Load(object sender, EventArgs e)
        {

            base.Page_Load(sender, e);

            if (IsPostBack)
                return;

            //foreach (KeyValuePair<String, Soveryn.Commerce.Shared.DoodadInstanceProperty> prop in UserProperties)
            //{
            //    if (prop.Key.ToLower().Contains("slide image") && !String.IsNullOrEmpty(prop.Value.Value.Trim()))
            //    {
            //        SlidesHTMLLiteral.Text += "<div><img src='" + prop.Value.Value + "' alt=''/></div>";
            //    }
            //}

            MatchCollection matchesImgSrc = Regex.Matches(Properties.DoodadInstanceHTML, @"<img[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            foreach (Match m in matchesImgSrc)
            {
                
                SlidesHTMLLiteral.Text += "<div><img src='" + DoodadUtils.ReplaceUserVars(m.Groups[1].Value, Properties, this.ParentPage.Website) + "' alt=''/></div>";
            }

        }

        public List<String> FetchLinksFromSource(string htmlSource)
        {
            List<String> links = new List<String>();
            string regexImgSrc = @"<img[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>";
            MatchCollection matchesImgSrc = Regex.Matches(htmlSource, regexImgSrc, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            foreach (Match m in matchesImgSrc)
            {
                links.Add(m.Groups[1].Value);
            }
            return links;
        }

    }

    

}
